package com.shuai.user.service.inner;

import com.shuai.common.dto.SessionChatRecordDTO;
import com.shuai.common.service.user.InnerSessionChatRecordService;
import com.shuai.user.domain.entity.SessionChatRecord;
import com.shuai.user.service.SessionChatRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
@DubboService
public class InnerSessionChatRecordServiceImpl implements InnerSessionChatRecordService {

    @Autowired
    private SessionChatRecordService sessionChatRecordService;


    /**
     * 保存会话
     */
    public boolean saveSessionChatRecord(SessionChatRecordDTO sessionChatRecordDTO) {
        SessionChatRecord sessionChatRecord = new SessionChatRecord();
        BeanUtils.copyProperties(sessionChatRecordDTO, sessionChatRecord);
        return sessionChatRecordService.save(sessionChatRecord);
    }

    public boolean saveSessionChatRecordBatch(List<SessionChatRecordDTO> sessionChatRecordDTOList) {
        List<SessionChatRecord> collect = sessionChatRecordDTOList.stream().map(sessionChatRecordDTO -> {
            SessionChatRecord sessionChatRecord = new SessionChatRecord();
            BeanUtils.copyProperties(sessionChatRecordDTO, sessionChatRecord);
            return sessionChatRecord;
        }).collect(Collectors.toList());
        return sessionChatRecordService.saveBatch(collect);
    }

}
